<template>
  <a-modal
    :open="open"
    width="800px"
    :title="rowData?.lsh ? '修改舰艇卫生' : '新增舰艇卫生'"
    centered
    :ok-button-props="{ disabled: !isCompleted }"
    ok-text="保存"
    @ok="onOk"
    @cancel="onCancel"
  >
    <a-form class="form-style-flex" name="validate_other" :model="formState" :label-col="{ style: { width: '100px' } }">
      <a-form-item label="舰艇名称" class="w-full" v-bind="validateInfos.shipName">
        <a-input v-model:value="formState.shipName" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="区域" class="w-full">
        <a-input v-model:value="formState.region" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="战位" class="w-full">
        <a-input v-model:value="formState.position" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="总体环境描述" class="w-full">
        <a-textarea v-model:value="formState.environment" :row="3" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="温度" class="w-2/6">
        <a-input v-model:value="formState.temperature" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="湿度" class="w-2/6">
        <a-input v-model:value="formState.humidity" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="震动" class="w-2/6">
        <a-input v-model:value="formState.vibrate" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="噪声" class="w-2/6">
        <a-input v-model:value="formState.noise" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="通风" class="w-2/6">
        <a-input v-model:value="formState.ventilate" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="光照" class="w-2/6">
        <a-input v-model:value="formState.illumination" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="异常气体" class="w-2/6">
        <a-input v-model:value="formState.abnormalGas" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="舒适度" class="w-2/6">
        <a-input v-model:value="formState.comfortable" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="作业效率" class="w-2/6">
        <a-input v-model:value="formState.workEfficiency" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="备注" class="w-full">
        <a-textarea v-model:value="formState.memo" :row="3" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'update:value', 'success'])

const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})

const formState = ref({
  shipName: ''
})
const rulesState = ref({
  shipName: [{ required: true, message: '请输入舰艇名称' }]
})
const { isCompleted, resetFields, validateInfos } = useForm(formState, rulesState)

const onOk = async () => {
  const { code, msg } = await post('/war/epidemicOtherPrevention/doSaveEpidemicHygiene', formState.value)
  if (code !== 0) return message.error(msg)
  message.success(msg)
  emit('update:open', false)
  emit('success')
}

const onCancel = () => {
  emit('update:open', false)
  resetFields()
}

watch(
  () => props.open,
  (val) => {
    if (val) {
      formState.value = { ...props.rowData }
    }
  }
)
</script>
<style lang="less" scoped></style>
